package vn.edu.saigontech.ncms.service.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import vn.edu.saigontech.ncms.model.info.SurveyInfo;
import vn.edu.saigontech.ncms.service.SurveyInfoService;

@SuppressWarnings("unchecked")
public class SurveyInfoServiceImpl extends HibernateGenericService<SurveyInfo, Long> implements SurveyInfoService {

	@Override
	public Collection<SurveyInfo> findAll() {
		Criteria criteria = this.createCriteria();
		criteria.addOrder(Order.asc("name"));
		return criteria.list();
	}
	
	public Collection<SurveyInfo> findAllAreActive() {
		Criteria criteria = this.createCriteria();
		criteria.add(Restrictions.eq("active", true));
		criteria.addOrder(Order.asc("name"));
		return criteria.list();
	}
	
	public SurveyInfo findByName(String name) {
		Criteria criteria = this.createCriteria();
		criteria.add(Restrictions.eq("name", name));
		return (SurveyInfo) criteria.uniqueResult();
	}
}